/**
 * 
 */
package com.zhuoan.im.server.expandprocessor;

import org.jim.common.ImAio;
import org.jim.common.ImPacket;
import org.jim.common.packets.Command;
import org.jim.common.utils.JsonKit;
import org.jim.server.command.handler.processor.handshake.WsHandshakeProcessor;
import org.springframework.stereotype.Component;
import org.tio.core.ChannelContext;

/**
 * 握手处理接口HandshakeProcessorIntf  +  不同协议CMD命令处理接口ProcessorIntf
 *
 * @author weixiang.wu
 * @date 2018-10-12 14:38
 **/
@Component
public class ImWsHandshakeProcessor extends WsHandshakeProcessor {

    /**
     * 握手成功后
     * @param packet
     * @param channelContext
     * @throws Exception
     */
	@Override
	public void onAfterHandshaked(ImPacket packet, ChannelContext channelContext) throws Exception {

        ImPacket loginRespPacket = new ImPacket(Command.COMMAND_LOGIN_RESP, JsonKit.toJsonBytes("握手成功后的回调"));
        ImAio.send(channelContext, loginRespPacket);


//		LoginReqHandler loginHandler = (LoginReqHandler) CommandManager.getCommand(Command.COMMAND_LOGIN_REQ);
//		HttpRequest request = (HttpRequest)packet;
//		String username = request.getParams().get("username") == null ? null : (String)request.getParams().get("username")[0];
//		String password = request.getParams().get("password") == null ? null : (String)request.getParams().get("password")[0];
//		String token = request.getParams().get("token") == null ? null : (String)request.getParams().get("token")[0];
//		LoginReqBody loginBody = new LoginReqBody(username,password,token);
//		byte[] loginBytes = JsonKit.toJsonBytes(loginBody);
//		request.setBody(loginBytes);
//		request.setBodyString(new String(loginBytes, HttpConst.CHARSET_NAME));
//		ImPacket loginRespPacket = loginHandler.handler(request, channelContext);
//		if(loginRespPacket != null){
//			ImAio.send(channelContext, loginRespPacket);
//		}
	}
}
